package com.demo.openlktest.service;

import com.demo.openlktest.dao.CheckDao;
import com.demo.openlktest.entity.po.CheckResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckService {

    public final static float RATIO_SET = 1.50F;

    @Autowired
    CheckDao checkDao;

    public void test() {
        checkDao.test();
    }

    public CheckResult check(String personID) {
        int recordsNum = checkDao.checkCreditRecords(personID);

        List<String> cards = checkDao.selectAllCardNumByPersonID(personID);
        float totalIncome = 0, totalOutcome = 0;
        for (int i = 0; i < cards.size(); i++) {
            totalIncome += checkDao.checkIncomeForOneYearByOneCard(personID, cards.get(i));
            totalOutcome += checkDao.checkOutcomeForOneYearByOneCard(personID, cards.get(i));
        }
        float ratio = totalIncome / totalOutcome;

        boolean is_radio_suitable = ratio > RATIO_SET ? true : false;
        boolean is_records_num_suitable = recordsNum <= 5 ? true : false;
        boolean suitable = is_radio_suitable == true && is_records_num_suitable == true ? true : false;

        CheckResult checkResult = new CheckResult();
        checkResult.setRatio(1.23);
        checkResult.setSuitable(false);
        return checkResult;
    }
}
